package com.gamatechno.solodestination;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;

import com.gamatechno.adapter.CustomGridViewAdapter;
import com.gamatechno.solodestination.model.DBHandler;
import com.gamatechno.solodestination.model.Event;
import com.gamatechno.solodestination.model.Favorite;
import com.gamatechno.solodestination.model.Item;
import com.gamatechno.solodestination.model.Item2;
import com.google.android.gms.internal.da;

import android.app.Fragment;
import android.content.Intent;
import android.os.Bundle;
import android.util.Log;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.AdapterView;
import android.widget.GridView;
import android.widget.AdapterView.OnItemClickListener;
import android.widget.ImageView;
import android.widget.Toast;

public class FovoriteFragment extends Fragment {

	public FovoriteFragment() {
	}

	List<Favorite> dataList;
	GridView grid;
	ArrayList<Item2> gridArray = new ArrayList<Item2>();

	@Override
	public View onCreateView(LayoutInflater inflater, ViewGroup container,
			Bundle savedInstanceState) {

		View rootView = inflater.inflate(R.layout.fragment_favorite, container,
				false);

		return rootView;
	}

	@Override
	public void onActivityCreated(Bundle savedInstanceState) {
		// TODO Auto-generated method stub
		super.onActivityCreated(savedInstanceState);
		DBHandler db = new DBHandler(getActivity());
		ArrayList<HashMap<String, Object>> list = new ArrayList<HashMap<String, Object>>();
		dataList = db.getFavorite();
		for (Favorite f : dataList) {
			gridArray.add(new Item2(f.getName(), f.getCategory(), String
					.valueOf(f.getRate()), f.getComments(), f.getImg()));
		}
		// gridArray
		// .add(new Item("Keraton Surakarta", "Wisata Budaya", "2", "21",
		// R.drawable.akunku_icon));
		// gridArray.add(new Item("Gudheg Ceker", "Kuliner", "3.5", "66",
		// R.drawable.akunku_icon));
		// gridArray.add(new Item("Stasiun Balapan", "Transportasi", "5", "21",
		// R.drawable.akunku_icon));
		// gridArray
		// .add(new Item("Pura Mangkunegaran", "Wisata Budaya", "1.5", "15",
		// R.drawable.akunku_icon));
		// gridArray.add(new Item("Best Western Premier",
		// "Hotel dan Penginapan",
		// "5", "21", R.drawable.akunku_icon));
		grid = (GridView) getActivity().findViewById(R.id.gridView1);
		CustomGridViewAdapter CustomGrid = new CustomGridViewAdapter(
				getActivity(), R.layout.row_grid, gridArray, getActivity());
		grid.setAdapter(CustomGrid);
		
		
		
		grid.setOnItemClickListener(new OnItemClickListener() {

			@Override
			public void onItemClick(AdapterView<?> arg0, View arg1,
					int position, long arg3) {
				// TODO Auto-generated method stub
				 Toast.makeText(getActivity(),
						 dataList.get(position).getCategory().toString(), Toast.LENGTH_SHORT)
				 .show();
				
				Intent i = new Intent(getActivity(), SubFavoriteActivity.class);
				i.putExtra("kategori", dataList.get(position).getCategory().toString());
				i.putExtra("id", dataList.get(position).getId().toString());
				
				startActivity(i);
				
				Log.i("fuu" ,dataList.get(position).getCategory().toString());
				Log.i("fuu id" ,dataList.get(position).getId().toString());
			}
		});

	}
}
